feat: bound Merkle proof depth at verification - #695
Merged
thlpkee20-wq merged 2 commits intoJul 29, 2026
Conversation
Add MAX_PROOF_DEPTH = 32 to merkle_helpers, reject oversized proofs
with ProofTooDeep error (wire value 77), emit proof_reject_depth
(prf_rej_d) event on rejection, and expose verify_merkle_proof as a
read-only, auth-free contract entrypoint.
Changes:
- src/merkle_helpers.rs
- Add MAX_PROOF_DEPTH: u32 = 32 constant (pub, documented)
- Add MerkleError::ProofTooDeep = 1003 variant
- Add verify_merkle_proof() helper with O(1) depth check before hashing
- Expand module-level docs with proof verification section
- src/lib.rs
- Add RevoraError::ProofTooDeep = 77 (frozen wire value)
- Add EVENT_PROOF_REJECT_DEPTH (symbol_short!("prf_rej_d")) constant
- Add pub fn verify_merkle_proof() contract entrypoint:
emits prf_rej_d + returns ProofTooDeep when proof.len() > 32
- Register test_merkle_proof_depth module
- src/test_merkle_proof_depth.rs (new)
- 18 tests covering: constant value, valid proofs, depth-bound
boundary (exactly 32 passes, 33 fails), contract entrypoint,
event emission, and build+verify round-trip integration
- docs/merkle-proof-depth-bound.md (new)
- Developer notes: rationale, API reference, error codes,
event schema, off-chain proof construction guide, and
change-compatibility table
Security: depth check fires before any SHA-256 call (O(1)),
preventing gas/memory exhaustion from adversarial deep proofs.
|
Hey @Bojest001! 👋 It looks like this PR isn't linked to any issue. If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g.,
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here's a concise PR description you can use:
───────────────────────────────────────────────────────────────────────────────────────────────
feat: bound Merkle proof depth at verification
Summary
Adds a hard upper limit on Merkle proof length at the verification entrypoint to prevent gas
exhaustion and memory overflow from adversarially crafted deep proofs.
What changed
src/merkle_helpers.rs
capping per-call cost
before any SHA-256 call
src/lib.rs
observe oversized-proof attempts
contract entrypoint
src/test_merkle_proof_depth.rs (new, 18 tests)
docs/merkle-proof-depth-bound.md (new)
guide, change-compatibility table
Security
The depth check is O(1) and runs before any hashing — an adversary cannot trigger expensive
computation by submitting an oversized proof vector.
Testing
cargo test -- --test-threads=1
All 18 new tests in test_merkle_proof_depth plus the full existing suite must pass.
▸ Closes#571